package com.mingyuan.library.domain.lending.patron.event;

import com.mingyuan.library.domain.lending.book.model.valueobject.BookId;
import com.mingyuan.library.domain.lending.librarybranch.model.valueobject.LibraryBranchId;
import com.mingyuan.library.domain.lending.patron.model.valueobject.PatronInformation;
import com.mingyuan.library.domain.lending.patron.model.valueobject.Rejection;
import lombok.NonNull;
import lombok.Value;

import java.time.Instant;
import java.util.UUID;

/**
 * 图书借阅失败信息
 *
 * @author yangzk
 * @date 2023/12/28 18:48
 **/
@Value
public class BookCheckingOutFailed implements PatronEvent {
    /**
     * 事件ID
     */
    @NonNull UUID eventId = UUID.randomUUID();
    /**
     * 原因
     */
    @NonNull String reason;
    /**
     * 什么时间
     */
    @NonNull Instant when;
    /**
     * 读者ID
     */
    @NonNull UUID patronId;
    /**
     * 图书ID
     */
    @NonNull UUID bookId;
    /**
     * 图书馆分馆ID
     */
    @NonNull UUID libraryBranchId;

    /**
     * 组装当前图书借阅失败
     *
     * @param rejection         拒绝值对象信息
     * @param bookId            图书ID
     * @param libraryBranchId   图书馆ID
     * @param patronInformation 读者信息
     * @author yangzk
     * @date 2023/12/28 18:50
     **/
    public static BookCheckingOutFailed bookCheckingOutFailedNow(Rejection rejection, BookId bookId, LibraryBranchId libraryBranchId, PatronInformation patronInformation) {
        return new BookCheckingOutFailed(
                rejection.getReason(),
                Instant.now(),
                patronInformation.getPatronId().getPatronId(),
                bookId.getBookId(),
                libraryBranchId.getLibraryBranchId());
    }
}